package Day13;

import java.util.*;

public class Main {
    //模拟
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0){
            int n = in.nextInt(), k = in.nextInt();
            char[] arr = in.next().toCharArray();
            int num = 0;
            int ans = 0;
            for(int i = 0; i < n; i++){
                if(arr[i] == 'L'){
                    ans--;
                    num = 0;
                }else{
                    num++;
                    if(num >= 3){
                        ans += k;
                    }else{
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }

    //滑动窗口+哈希
    public int maxLength (int[] arr) {
        HashMap<Integer, Integer> hash = new HashMap<>();
        int l = 0;
        int r = 0;
        int ans = 0;
        for(r = 0; r < arr.length; r++){
            if(hash.get(arr[r]) == null){
                hash.put(arr[r], 1);
                ans = Math.max(ans, r - l + 1);
            }else{
                while(hash.get(arr[r]) != null){
                    hash.remove(arr[l]);
                    l++;
                }
            }
        }
        return ans;
    }

    //重排字符串
    //桶思想

}
